package com.github.zyflzz.mycalculator.recyclerview;

import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import org.jetbrains.annotations.Contract;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author created by zyf on 2023/3/24
 **/
public class Record {

    private final String time;

    private final String input;

    private final String result;

    private final Integer inputSize;
    private final Integer resultSize;

    @RequiresApi(api = Build.VERSION_CODES.O)
    public Record(String input, String result) {
        this.time = DateTimeFormatter.ofPattern("yyyy/MM/dd hh:mm:ss").format(LocalDateTime.now());
        this.input = input;
        this.result = "= " + result;
        this.inputSize = setSize(input);
        this.resultSize = setSize(result);
    }

    public String getTime() {
        return time;
    }

    public String getInput() {
        return input;
    }

    public String getResult() {
        return result;
    }

    @NonNull
    @Contract(pure = true)
    private Integer setSize(@NonNull String input) {
        int len = input.length();
        if (len < 10) {
            return 18;
        } else if (len < 30) {
            return 12;
        } else {
            return 9;
        }
    }

    public Integer getInputSize() {
        return inputSize;
    }

    public Integer getResultSize() {
        return resultSize;
    }
}
